﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Web;
using WLFramework.Json;
using GenericHtml;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getUserPositionsByUser 的摘要说明
    /// </summary>
    public class getUserPositionsByUser : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int? uid = context.GetValueByName<int?>("U_ID");
            if (uid == null)
                return;

            using (var db = new PermissionContext())
            {
                var positions = db.View_UserPosition.Where(k => k.U_ID == uid && k.P_State == 1);
                
                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = positions.Count(),
                    rows = positions.Select(k => new
                    {
                        U_ID = k.U_ID,
                        P_ID = k.P_ID,
                        IsMain = k.IsMain,
                        P_State = k.P_State
                    }).ToList()
                }));
            }
        }
    }
}